<template>
	<scroll-view class="content" scroll-y>
		<view class="single-data" v-for="item in cadList" :key="item.id" @click="jumpMain(item.id)">
			<view class="single-name">
			{{item.name}}
			</view>
			<view class="del" @click.prevent.stop="delData(item.id)">
				删除
			</view>
		</view>
		<view class="add-btn" @click="jumpMain(null)">
			+
		</view>
	</scroll-view>
	
</template>

<script>
	export default {
		data() {
			return {
				cadList:[]
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList(){
				const that = this
				uni.request({
					url:'https://cad.hxjykt.com/cl/cad/list',
					
					method:'POST',
					
					data:JSON.stringify({ userId: '111111' }),
					success:function(res){
						that.cadList = res.data.data
					}
				})
			},
			jumpMain(id){
				if(id){
					uni.navigateTo({
						url:`/pages/index/index?id=${id}`
					})
				}else{
					uni.navigateTo({
						url:`/pages/index/index?id=a`
					})
				}
				
			},
			delData(id){
				const that = this
				uni.showModal({
					title:'确认删除？',
					success(res) {
						if(res.confirm){
							uni.request({
								url:'https://cad.hxjykt.com/cl/cad/'+id,
								
								method:'DELETE',
								// header: {
								//    'Content-Type': 'application/x-www-form-urlencoded'
								//  },
								
								success:function(res){
									that.getList()
								}
							})
						}
						
					},
					
				})
			}
		}
	}
</script>

<style scoped>
	.content{
		padding:50rpx 10rpx;
		box-sizing: border-box;
		height:100vh
	}
.single-data{
	border:1rpx solid #ccc;
	border-radius:10rpx;
	display: flex;
	justify-content: space-between;
	
}
.add-btn{
	position: fixed;
	bottom:50rpx;
	right:50rpx;
	border-radius: 50%;
	background: limegreen;
	width:80rpx;
	height:80rpx;
	text-align: center;
	line-height: 80rpx;	
}
</style>
